package com.xnx.bincker.leader.service.impl;

import com.xnx.bincker.leader.domain.User;
import com.xnx.bincker.leader.service.UserService;
import com.xnx.bincker.leader.utils.SpringUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Example;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@Log4j2
public class UserServiceImpl extends BasicServiceImpl<User, String> implements UserService {

	@Override
	public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
		User user = new User();
		user.setUsername(s);
		return repository.findOne(Example.of(user)).orElseThrow(()->new UsernameNotFoundException("用户不存在"));
	}

	/**
	 * 查找用户，通过用户名
	 * @param username 用户名
	 */
	public Optional<User> findUserByUsername(String username){
		User user = new User();
		user.setUsername(username);
		return repository.findOne(Example.of(user));
	}
}
